#ifndef __SOUNDMANAGER__
#define __SOUNDMANAGER__

#	include <cstdio>
#	include "../include/al/al.h"
#	include "../include/al/alc.h"
#   pragma comment(lib, "openal32.lib")
#	include "../Utilities/utilities.h"

struct RIFF_Header {
	char chunkID[4];
	long chunkSize;//size not including chunkSize or chunkID
	char format[4];
};

struct WAVE_Format {
	char subChunkID[4];
	long subChunkSize;
	short audioFormat;
	short numChannels;
	long sampleRate;
	long byteRate;
	short blockAlign;
	short bitsPerSample;
};

struct WAVE_Data {
	char subChunkID[4]; //should contain the word data
	long subChunk2Size; //Stores the size of the data block
};

bool loadWavFile(char* filename, unsigned char* &data, ALsizei* size, ALsizei* frequency, ALenum* format);


struct Sound
{
	ALuint buffer;
	ALuint source;
};

class SoundManager
{
private:
	static SoundManager* m_pThis;
	ALCdevice* m_pDevice;
	ALCcontext* m_pContext;
	Sound* listSound[10];
	int count = 0;
public:
	static SoundManager* getInstance()
	{
		if (!m_pThis)
			m_pThis = new SoundManager;
		return m_pThis;
	}
	Sound* Load(char* file_name);
	void SetPositionAttribute(Sound sound, Vector3 sound_position, Vector3 sound_velocity,
		Vector3 listener_position, Vector3 listener_velocity,
		Vector3 listener_orientation, Vector3 listener_up_vector
		);
	void SetSoundAttribute(Sound sound, ALfloat pitch, ALfloat gain);

	void Play(Sound sound, bool loop);
	void Pause(Sound sound);
	void Stop(Sound sound);
	bool isPlaying(Sound sound);
	void releaseSource(Sound sound);

	int Load();
	void Play(int index);
	//void delete
	~SoundManager();
private:
	SoundManager();
};

#endif